<template>
  <div class="page-container">
    <SearchPanel @change="handleSearchPanelChange">
      <el-form
        ref="queryForm"
        class="query-more-form"
        size="mini"
        label-width="100px"
        :model="query"
      >
        <el-row :gutter="21">
          <el-col :span="5">
            <el-form-item label="姓名">
              <el-input
                v-model="query.name"
                class="search-ipt"
                placeholder="请输入姓名"
                maxlength="255"
              />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="时间区间">
              <el-date-picker
                v-model="query.startTime"
                type="datetimerange"
                size="mini"
                range-separator="-"
                start-placeholder="开始"
                end-placeholder="结束"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4" class="btn-col">
            <el-button size="mini" class="search-btn" @click="select"
              >查询</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </SearchPanel>
    <div class="table-container">
      <div class="table-tools-panel table-flex-row">
        <div class="table-btns-left">
          <el-button class="flush-btn" icon="el-icon-refresh" @click="refresh"
            >刷新</el-button
          >
        </div>
        <div>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-set-up"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-share"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-printer"
          ></el-button>
        </div>
      </div>
      <div class="table-list-panel">
        <el-table
          v-loading="tableLoading"
          border
          size="small"
          :data="tableData"
          :height="isShow ? 'calc(100vh - 455px)' : 'calc(100vh - 380px)'"
          style="width: 100%"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column
            prop="departmentId"
            label="部门ID"
            show-overflow-tooltip
          /><el-table-column
            prop="departmentName"
            label="部门名称"
            show-overflow-tooltip
          />
            <!-- prop="attachmentPath" -->
          <!-- <el-table-column
            label="附件路径"
            show-overflow-tooltip
          /> -->
          <el-table-column label="操作" width="90" fixed="right">
            <template slot-scope="scope">
              <a
                class="fileName"
                :href="scope.row.attachmentPath"
              >详情</a>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-panel">
        <Pagination
          :total="query.total"
          :page.sync="query.pageNum"
          :limit.sync="query.pageSize"
          @pagination="select"
        />
      </div>
    </div>
  </div>
</template>

<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import { getDepartments } from "@/api/system/listing";

export default {
  name: "listing",
  components: {
    SearchPanel,
    Pagination
  },
  data() {
    return {
      visible: false,
      query: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        type: 1,
        name: ""
      },
      tableLoading: false,
      tableData: [],
      department: [],
      isShow: true,
      dialogType: "detail",
      obj: {}
    };
  },
  created() {
    this.initData();
  },
  methods: {
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    initData() {
      this.select();
    },
    select() {
      // 数据加载提示
      const query = JSON.parse(JSON.stringify(this.query));
      this.tableLoading = true;
      getDepartments(this.query)
        .then(result => {
          this.tableLoading = false;
          this.query.total = result.total;
          this.tableData = result.rows;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    // 刷新页面
    refresh() {
      this.query = {
        total: 1,
        pageNum: 1,
        pageSize: 10,
        type: 1,
        name: ""
      };
      this.select();
    },
    // 详情
    handDetail(row) {
      // this.dialogType = "detail";
      this.visible = true;
      this.obj = row;
    }
  }
};
</script>

<style lang="scss" scoped>
.fileName{
  color: #1890ff;
}
</style>